<?php
namespace App\Http\Controllers;

use App\Http\Controllers\WebController;
use App\Http\Controllers\Business\UserModule;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Facades\Excel;
use Log;

class UserController extends WebController
{
    public function login() {
        return view('login');
    }
    public function submitLoginData() {
        $password = $this->request->get('password');
        $phone = $this->request->get('phone');
        $result = UserModule::login($phone, $password);
        if($result['status'] == 'failed') {
            //return $this->responseError($result['message']);
            return redirect()->to('/login');
        }
        $userId = $result['data']['user_id'];
        $result = Auth::loginUsingId($userId);
        Log::INFO($result);
        //Log::INFO("user_id:".$userId);
        //return $this->responseSuccessMessage('登录成功');
        return redirect()->to('/index');
    }
    public function logout() {
        Auth::logout();
        return redirect()->to('login');
    }
}